`
https://leetcode.cn/problems/count-pairs-whose-sum-is-less-than-target/
`

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var countPairs = function (nums, target) {
  nums.sort((a, b) => a - b)
  const n = nums.length
  let res = 0
  let left = 0, right = n - 1

  while (left < right) {
    if (nums[left] + nums[right] < target) {
      // nums[left + 1, right] 和 nums[left] 都是合法对
      res += right - left
      left++
    } else {
      right--
    }
  }

  return res
};